// SPDX-License-Identifier: MIT
// Copyright (C) 2018-present iced project and contributors

package com.github.icedland.iced.x86.fmt.intel;

import com.github.icedland.iced.x86.internal.IcedConstants;
import com.github.icedland.iced.x86.internal.fmt.FormatterString;

final class MemorySizes {
	public static final class Info {
		public final FormatterString[] keywords;
		public final FormatterString bcstTo;

		Info(FormatterString[] keywords, FormatterString bcstTo) {
			this.keywords = keywords;
			this.bcstTo = bcstTo;
		}
	}

	static final Info[] allMemorySizes = getMemorySizes();

	private static Info[] getMemorySizes() {
		// GENERATOR-BEGIN: ConstData
		// ⚠️This was generated by GENERATOR!🦹‍♂️
		final int BROADCAST_TO_KIND_SHIFT = 5;
		final int MEMORY_KEYWORDS_MASK = 31;
		FormatterString byte_ = new FormatterString("byte");
		FormatterString ptr = new FormatterString("ptr");
		FormatterString[] byte_ptr = new FormatterString[] { byte_, ptr };
		FormatterString dword = new FormatterString("dword");
		FormatterString[] dword_ptr = new FormatterString[] { dword, ptr };
		FormatterString fpuenv14 = new FormatterString("fpuenv14");
		FormatterString[] fpuenv14_ptr = new FormatterString[] { fpuenv14, ptr };
		FormatterString fpuenv28 = new FormatterString("fpuenv28");
		FormatterString[] fpuenv28_ptr = new FormatterString[] { fpuenv28, ptr };
		FormatterString fpustate108 = new FormatterString("fpustate108");
		FormatterString[] fpustate108_ptr = new FormatterString[] { fpustate108, ptr };
		FormatterString fpustate94 = new FormatterString("fpustate94");
		FormatterString[] fpustate94_ptr = new FormatterString[] { fpustate94, ptr };
		FormatterString fword = new FormatterString("fword");
		FormatterString[] fword_ptr = new FormatterString[] { fword, ptr };
		FormatterString qword = new FormatterString("qword");
		FormatterString[] qword_ptr = new FormatterString[] { qword, ptr };
		FormatterString tbyte = new FormatterString("tbyte");
		FormatterString[] tbyte_ptr = new FormatterString[] { tbyte, ptr };
		FormatterString word = new FormatterString("word");
		FormatterString[] word_ptr = new FormatterString[] { word, ptr };
		FormatterString xmmword = new FormatterString("xmmword");
		FormatterString[] xmmword_ptr = new FormatterString[] { xmmword, ptr };
		FormatterString ymmword = new FormatterString("ymmword");
		FormatterString[] ymmword_ptr = new FormatterString[] { ymmword, ptr };
		FormatterString zmmword = new FormatterString("zmmword");
		FormatterString[] zmmword_ptr = new FormatterString[] { zmmword, ptr };
		FormatterString mem384 = new FormatterString("mem384");
		FormatterString[] mem384_ptr = new FormatterString[] { mem384, ptr };
		FormatterString empty = new FormatterString("");
		FormatterString b1to2 = new FormatterString("1to2");
		FormatterString b1to4 = new FormatterString("1to4");
		FormatterString b1to8 = new FormatterString("1to8");
		FormatterString b1to16 = new FormatterString("1to16");
		FormatterString b1to32 = new FormatterString("1to32");
		// GENERATOR-END: ConstData

		Info[] infos = new Info[IcedConstants.MEMORY_SIZE_ENUM_COUNT];
		byte[] data = new byte[] {
			// GENERATOR-BEGIN: MemorySizes
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			(byte)0x00,
			(byte)0x01,
			(byte)0x0A,
			(byte)0x02,
			(byte)0x08,
			(byte)0x08,
			(byte)0x0B,
			(byte)0x0C,
			(byte)0x0D,
			(byte)0x01,
			(byte)0x0A,
			(byte)0x02,
			(byte)0x08,
			(byte)0x0B,
			(byte)0x0C,
			(byte)0x0D,
			(byte)0x02,
			(byte)0x07,
			(byte)0x09,
			(byte)0x0A,
			(byte)0x02,
			(byte)0x08,
			(byte)0x02,
			(byte)0x08,
			(byte)0x08,
			(byte)0x0B,
			(byte)0x07,
			(byte)0x07,
			(byte)0x0A,
			(byte)0x02,
			(byte)0x08,
			(byte)0x09,
			(byte)0x0B,
			(byte)0x0A,
			(byte)0x03,
			(byte)0x04,
			(byte)0x06,
			(byte)0x05,
			(byte)0x00,
			(byte)0x00,
			(byte)0x00,
			(byte)0x00,
			(byte)0x09,
			(byte)0x0D,
			(byte)0x00,
			(byte)0x09,
			(byte)0x0E,
			(byte)0x0D,
			(byte)0x0A,
			(byte)0x0A,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x02,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x08,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0B,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0C,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x0D,
			(byte)0x2A,
			(byte)0x22,
			(byte)0x22,
			(byte)0x4A,
			(byte)0x22,
			(byte)0x6A,
			(byte)0x6A,
			(byte)0x42,
			(byte)0x42,
			(byte)0x28,
			(byte)0x28,
			(byte)0x28,
			(byte)0x6A,
			(byte)0x42,
			(byte)0x28,
			(byte)0x42,
			(byte)0x28,
			(byte)0x28,
			(byte)0x42,
			(byte)0x42,
			(byte)0x8A,
			(byte)0x8A,
			(byte)0x62,
			(byte)0x62,
			(byte)0x48,
			(byte)0x48,
			(byte)0x48,
			(byte)0x8A,
			(byte)0x62,
			(byte)0x48,
			(byte)0x62,
			(byte)0x48,
			(byte)0x48,
			(byte)0x62,
			(byte)0x62,
			(byte)0xAA,
			(byte)0xAA,
			(byte)0x82,
			(byte)0x82,
			(byte)0x68,
			(byte)0x68,
			(byte)0x68,
			(byte)0xAA,
			(byte)0x82,
			(byte)0x68,
			(byte)0x82,
			(byte)0x82,
			(byte)0x68,
			(byte)0x68,
			(byte)0x82,
			// GENERATOR-END: MemorySizes
		};

		for (int i = 0; i < infos.length; i++) {
			int d = data[i] & 0xFF;
			FormatterString[] keywords;
			FormatterString bcstTo;
			switch (d & MEMORY_KEYWORDS_MASK) {
			// GENERATOR-BEGIN: MemoryKeywordsSwitch
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			case 0x00:
				keywords = new FormatterString[0];
				break;
			case 0x01:
				keywords = byte_ptr;
				break;
			case 0x02:
				keywords = dword_ptr;
				break;
			case 0x03:
				keywords = fpuenv14_ptr;
				break;
			case 0x04:
				keywords = fpuenv28_ptr;
				break;
			case 0x05:
				keywords = fpustate108_ptr;
				break;
			case 0x06:
				keywords = fpustate94_ptr;
				break;
			case 0x07:
				keywords = fword_ptr;
				break;
			case 0x08:
				keywords = qword_ptr;
				break;
			case 0x09:
				keywords = tbyte_ptr;
				break;
			case 0x0A:
				keywords = word_ptr;
				break;
			case 0x0B:
				keywords = xmmword_ptr;
				break;
			case 0x0C:
				keywords = ymmword_ptr;
				break;
			case 0x0D:
				keywords = zmmword_ptr;
				break;
			case 0x0E:
				keywords = mem384_ptr;
				break;
			// GENERATOR-END: MemoryKeywordsSwitch
			default:
				throw new UnsupportedOperationException();
			}
			switch (d >>> BROADCAST_TO_KIND_SHIFT) {
			// GENERATOR-BEGIN: BroadcastToKindSwitch
			// ⚠️This was generated by GENERATOR!🦹‍♂️
			case 0x00:
				bcstTo = empty;
				break;
			case 0x01:
				bcstTo = b1to2;
				break;
			case 0x02:
				bcstTo = b1to4;
				break;
			case 0x03:
				bcstTo = b1to8;
				break;
			case 0x04:
				bcstTo = b1to16;
				break;
			case 0x05:
				bcstTo = b1to32;
				break;
			// GENERATOR-END: BroadcastToKindSwitch
			default:
				throw new UnsupportedOperationException();
			}
			infos[i] = new Info(keywords, bcstTo);
		}

		return infos;
	}
}
